import {GET_LIST_DATA} from '../actions/actionType.js'

const initialState = {
  lists: [],
  filterData: null,
  page: 0,
  isend: false
}

const getListData = (state, action) => {
  let _listData = []
  let _filterData = action.filterData || state.filterData
  let _page = action.toFirstPage ? 0 : state.page
  let _isend = false
  if(_page === 0){
    _listData = action.obj.data.poilist
  }else{
    let newlists = action.obj.data.poilist
    _listData = state.lists.concat(newlists)
  }
  _page = _page + 1
  if(_page > 3){
    _isend = true
  }
  return {...state, lists: _listData, filterData: _filterData, page: _page, isend: _isend}
}

const contentListReducer = (state = initialState, action) => {
  switch(action.type){
    case GET_LIST_DATA:
      return getListData(state, action)
    default:
      return state
  }
}

export default contentListReducer